package be.ipl.diavoloz.daoimpl;

import java.util.Iterator;
import java.util.List;

import javax.ejb.Stateless;

import be.ipl.diavoloz.dao.TourDao;
import be.ipl.diavoloz.modele.De;
import be.ipl.diavoloz.modele.Demons;
import be.ipl.diavoloz.modele.Joueur;
import be.ipl.diavoloz.modele.Partie;
import be.ipl.diavoloz.modele.Tour;


@SuppressWarnings("serial")
@Stateless
public class TourDaoImpl extends DaoImpl<Integer, Tour> implements TourDao{

	@Override
	public Tour obtenirTour(int id) {
		String queryString = "SELECT t from Tour t where t.id_tour = ?1";
		return recherche(queryString, id);
	}

	@Override
	public void supprimerTable() {
		String queryString = "SELECT d from Tour";
		List<Tour> l = liste(queryString, null);
		Iterator<Tour> it = l.iterator();
		while(it.hasNext()){
			Tour d = (Tour) it.next();
			supprimer(d.getId());
		}	
	}
	
	@Override
	public List<Demons> rechercherListeDemon(Tour t){
		Tour tour = recharger(t.getId());
		return tour.getDemons();
	}
	
	@Override
	public List<De> rechercherListeDe(Tour t){
		Tour tour = recharger(t.getId());
		return tour.getDes();
	}
	
	@Override
	public String recupererDeOrdre(int tourId){
		Tour tour = recharger(tourId);
		return tour.getIntituleDeOrdre();
	}

}
